package com.hxkj.controller.wechat;

import com.hxkj.domain.po.Applet;
import com.hxkj.domain.po.AppletAgent;
import com.hxkj.domain.po.AppletAgentArticle;
import com.hxkj.domain.po.AppletArticle;
import com.hxkj.service.wechat.AppletArticlePushService;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Callable;

/**
 * @ClassName AppletArticlePushController
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/6/12 14:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/articlepush")
public class AppletArticlePushController {

    @Autowired
    private AppletArticlePushService appletArticlePushService;
    /**
     * @author Mr.zheng
     * @Description saveAgentArticle 保存用户与文章的关联信息
     * @Date 14:22 2018/6/12
     * @Param [appletAgentArticle]
     * @return com.platform.common.domain.result.ResultMessageStruct
     **/
    @RequiresPermissions("articlepush:add")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void saveAgentArticle(@ModelAttribute AppletAgentArticle appletAgentArticle) throws Exception{
        appletArticlePushService.saveAgentArticle(appletAgentArticle);
    }

    /**
    * @author Mr.zheng
    * @Description getHaveAgentArticle 获取已发布的文章
    * @Date 18:33 2018/6/12
    * @Param [appletAgentArticle, pageParam]
    * @return java.util.concurrent.Callable<com.platform.common.domain.result.ResultPageStruct<com.hxkj.domain.po.AppletArticle>>
    **/
    @RequiresPermissions("articlepush:view")
    @RequestMapping(value = "/gethavelist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<AppletArticle>> getHaveAgentArticle(@ModelAttribute AppletAgentArticle appletAgentArticle, @ModelAttribute PageTo pageParam) throws Exception{
        return () -> appletArticlePushService.getHaveAgentArticle(appletAgentArticle,pageParam);
    }

    /**
    * @author Mr.zheng
    * @Description getNotAgentArticle 获取未发布的文章
    * @Date 18:33 2018/6/12
    * @Param [appletAgentArticle, pageParam]
    * @return java.util.concurrent.Callable<com.platform.common.domain.result.ResultPageStruct<com.hxkj.domain.po.AppletArticle>>
    **/
    @RequiresPermissions("articlepush:view")
    @RequestMapping(value = "/getnotlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<AppletArticle>> getNotAgentArticle(@ModelAttribute AppletAgentArticle appletAgentArticle, @ModelAttribute PageTo pageParam) throws Exception{
        return () -> appletArticlePushService.getNotAgentArticle(appletAgentArticle,pageParam);
    }

    /**
    * @author Mr.zheng
    * @Description getAppletByAgentId 根据用户ID获取小程序下来框
    * @Date 15:33 2018/6/13
    * @Param [appletAgentArticle, pageParam]
    * @return java.util.concurrent.Callable<com.platform.common.domain.result.ResultPageStruct<com.hxkj.domain.po.AppletArticle>>
    **/
    @RequiresPermissions("articlepush:view")
    @RequestMapping(value = "/getapplet", method = RequestMethod.POST)
    public Callable<ResultPageStruct<Applet>> getAppletByAgentId(@ModelAttribute AppletAgent appletAgent, @ModelAttribute PageTo pageParam) throws Exception{
        return () -> appletArticlePushService.getAppletByAgentId(appletAgent,pageParam);
    }
}
